package com.example.shirotest.console;

import com.example.shirotest.utils.ToolUtil;

public class Product extends Thread{

    //private ShareData shareData;
    private GetRemoteData shareData;

    public Product(String name,GetRemoteData getRemoteData){
        super(name);
        this.shareData = getRemoteData;
    }

    @Override
    public void run() {
        Integer waittime = 2000;
        Integer size = 0;
        while (true){
            size = shareData.getData().size();
            if(size > 0){
                System.out.println(ToolUtil.getCurDateTimeStr() + Thread.currentThread().getName()+ " say: Queue have " + size + " data , wait 5s ");
                waittime = 5000;
            }else {
                System.out.println(ToolUtil.getCurDateTimeStr() + Thread.currentThread().getName()+ " say: Queue is empty , push data ");
                shareData.loadSite();
                if(shareData.getIsEnd()){
                    shareData.setStartId(0);
                    System.out.println(ToolUtil.getCurDateTimeStr() + Thread.currentThread().getName()+ " say: No more load , I will finished ");
                    break;
                }
                waittime = 2000;
            }

            try {
                Thread.sleep(waittime);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
